package com.cx.thread;

import java.util.concurrent.*;

public class CallablePool1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //最大线程数设置为5，队列最大能存3，使用主线程执行的拒绝策略
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 5, 10,
                TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(3),
                new ThreadPoolExecutor.CallerRunsPolicy());
        int n = 5;
        for(int i = 0; i < 6;i ++) {
            // 提交【例6-2-5】线程任务
            Future<Integer> result = threadPoolExecutor.submit(new MyCallable(i * 100));

            System.out.println("执行当前任务的线程：" + Thread.currentThread().getName()  );
        }
        //关闭线程池
        threadPoolExecutor.shutdown();
        //如果没有中断就一直等待
        while(!threadPoolExecutor.isTerminated()){
        }
    }
}